﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NFit.Core.Interfaces;

namespace NFit.Core.Test.IO
{
    class SampleSpecificationCheck
    {
        public static void ExecuteFromText(ISpecificationReader reader, string ressourceFileName)
        {
            string specText = Helper.LoadFromRessourceFile(ressourceFileName);
            SpecificationDefinition spec = reader.ReadSpecification(specText);

            CheckSpecification(spec);
        }

        public static void ExecuteFromStream(ISpecificationReader reader, string ressourceFileName)
        {
            SpecificationDefinition spec = null;
            Helper.UseRessourceStream(
                ressourceFileName,
                input =>
                {
                    spec = reader.ReadSpecification(input);
                }
            );

            CheckSpecification(spec);
        }

        public static void CheckSpecification(SpecificationDefinition spec)
        {
            CheckSpecification(spec, true);
        }

        public static void CheckSpecification(SpecificationDefinition spec, bool checkComments)
        {
            Assert.AreEqual(4, spec.Fixtures.Count);

            if (checkComments)
            {
                foreach (var fixture in spec)
                {
                    Assert.AreEqual(fixture.Header, "this is a fixture text header");
                    Assert.AreEqual(fixture.Footer, "this is a fixture text footer");
                }
            }

            DefaultSpecificationExecution runner = new DefaultSpecificationExecution();
            runner.Run(spec);

            Assert.IsTrue(spec.IsSuccessful);
            Assert.AreEqual(3, spec.Fixtures.Count);
        }
    }
}
